package com.farah.lease.common.exception;

import com.farah.lease.common.result.ResultCodeEnum;
import lombok.Data;

/**
 * @Author 不爱跑步的法拉韶
 * @Date 2024-06-24__12:03
 **/
@Data
public class LeaseException extends RuntimeException{

    /**
     * 异常状态码
     */
    private Integer code;

    /**
     * 通过状态码和错误信息创建异常对象
     * @param message 错误信息
     * @param code 状态码
     */
    public LeaseException(String message,Integer code){
        super(message);
        this.code = code;
    }

    /**
     * 根据响应结果枚举构建异常对象
     * @param resultCodeEnum 响应结果枚举
     */
    public LeaseException(ResultCodeEnum resultCodeEnum){
        super(resultCodeEnum.getMessage());
        this.code=resultCodeEnum.getCode();
    }

    @Override
    public String toString(){
        return "LeaseException{code="+code+", message="+this.getMessage()+"}";
    }
}
